<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm() {
        $("#form_recharge").bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                rechargeAmount: {
                    validators: {
                        notEmpty: {message: "充值金额不可为空"},
                        regexp: {
                            regexp: validateUtil.money,
                            message: '金额格式错误'
                        }
                    }
                }
            }
        });
    }

    /**
     * 表单提交及验证初始化
     */
    $(document).ready(function() {
        if($("#form_recharge").length>0){ /**判断当前页面是否有填写表单并检验**/
        validateForm();
            /**Modal验证销毁重构**/
            $('#rechargeModal').on('hidden.bs.modal', function() {
                reValidateForm();
            });
        }
    });

    /**
     * 重置表单验证
     */
    function reValidateForm(){
        $("#form_recharge").data('bootstrapValidator', null);
        validateForm();
    }

    /**
     * 表单异步提交
     */
    var isValid;
    function submitFormRecharge(){
        /** 开启验证**/
        $("#form_recharge").data('bootstrapValidator').validate();
        isValid=$("#form_recharge").data('bootstrapValidator').isValid();
        if(isValid){  /** 验证通过后提交表单**/
        var options = {
                url: $("#form_recharge").attr("action"),
                type : "post",
                dataType:"json",
                success : function(data) {
                    if(data.success==true){
                        /** 先重置查询框的值**/
                        $("#qform")[0].reset();
                        /** 重新刷新列表数据**/
                        $("#tt").bootstrapTable('refresh');
                        /** 自动关闭弹出模态框窗口**/
                        $(".close").click();
                        showMsg("保存成功！");
                    }else{
                        showMsg("保存失败！");
                    }
                }
            };
            $("#form_recharge").ajaxSubmit(options);
        }else{ /** 验证失败了直接返回 **/
            return ;
        }
    }

    /**
     * 会员余额充值
     */
	<shiro:hasPermission name="back_gotoCustomerPage_recharge">
    function rechargeInfo() {
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            if(selectedRow[0].type==2){/**供应商**/
                showMsg("店铺会员不能充值！");
            }else if(selectedRow[0].type==1||selectedRow[0].type==3) {/**企业用户和普通会员**/
                $("#btn_recharge").attr("data-target", "#rechargeModal");/**选中了记录后才可打开对应的模态框**/
                /**隐藏域**/
                $("#recharge_customerId").val(selectedRow[0].customerId);
                /**可见表单控件**/
                $("#rechargeAmount").val("");
            }
        } else {
            $("#btn_recharge").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
	</shiro:hasPermission>
</script>

<!--模态框（Modal） -->
<div class="modal fade" id="rechargeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel">会员余额充值</h5>
			</div>
			<div class="modal-body">
				<form id="form_recharge" method="post" action="${basePath}/back/customer/gotoRechargeMoney.sjson">
					<input id="recharge_customerId" type="hidden" name="customerId" noclear="true"/>
					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>充值金额:&nbsp;&nbsp;</td>
							<td class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="rechargeAmount" name="rechargeAmount" placeholder="请输入充值金额"/>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary" onclick="submitFormRecharge()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
